Getting started

And thus, Advent of Code begins!

Nvim Homework

Pairing delimiters

windwp/nvim-autopairs did the trick. I now get paired delimiters, and overwriting a closing delimiter doesn't duplicate it.

Writing into an empty block

windwp/nvim-autopairs actually solves this one too. When I place my cursor in a {}, press Enter, it'll put the opening and closing on separate lines, with a newline inbetween.

Diagnostics listing only shows problems in current file

Still unsolved.

LSP action rename doesn't save files

Still unsolved, but won't be a problem for AoC, I think. I almost always operate within one file for these.

Scroll-off threshold

Yeah, I just set it. Easy as that.

Scrolling without moving cursor (too much)

No, I'm still bad. Though I've been using searches and ]/[-based motions more.

New stuff

After some searching and trying out stuff, I installed kylechui/nvim-surround, a general-purpose delimiter editing plugin. It also brings a bunch of commands to add, remove, or modify pairs of delimiters around your cursor.

For example, you could put parentheses around the current word with ysiw), where ys is the command, iw is the text object to surround, and ) is the type of delimiter to use.

I didn't like the original keybinds (hijacking y, c and d like it does), so I remapped it all to be sa (surround add), sd (surround delete) and sc (surround change). Having it in it's own "folder" makes more sense to my brain, rather than attaching a non-yanking operation to y.

New issues

I can't really think of anything right now.

The task itself

Code

The first part is largely trivial. Just find the first and last digit in a string, and do some calculations/summing with them.

I was surprised at how tricky the second part was, though. It now requires you to also count digits written as text. That's not that bad, easiest way is probably string replaces (from text -> number)... except, textual digits can overlap, so no matter which order you do the replaces in, you might get it wrong.

Examle

eightwo => 82, but doing either replace first will leave you with either a dangling "eigh" or "wo".

Instead of replacing one => 1, I just did one => o1ne, and the same for all further digits. That way it preserves adjacent overlapping words, and you get all the numbers in there, in the right order. After that, you can calculate the score the same way as in part 1.

I don't know if I remember it wrong, but I don't recall previous day 1s having a major wrinkle like that. Neat!